$(function () {
        var AppObject = function () {
            this.clientType = null;
            this.product_id = 0;
            this.store_id = 0;
            this.oshop_id = (typeof oshop_id == 'undefined') ? "" : oshop_id;
            this.initStyle();
            this.getClientType();
        };

        AppObject.prototype.initStyle = function(){
            $(".C_J_good").css({"cursor": "pointer"});
        };

        AppObject.prototype.getClientType = function () {
            var u = navigator.userAgent;
            var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //android终端或者uc浏览器
            var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端

            this.clientType = isAndroid ? "android" : (isIOS ? "ios": null);

            this.addEventListen();
        };

        AppObject.prototype.addEventListen = function () {
            this.goodClickEvent();
        };

        /**
         * 商品详情事件
         * @return {[type]} [description]
         */
        AppObject.prototype.goodClickEvent = function(){
            var self = this;
            $(document).on('click', '.C_J_good', function () {
                
                self.product_id = $(this).data("id");
                self.store_id = ($(this).data("sid") == undefined ? 0: $(this).data("sid"));
                
                if (null === self.clientType) {
                    self.toHtmlDetail();
                }else{
                    if ("ios" == self.clientType) {
                        self.toIosDetail();
                    }else if("android" == self.clientType) {
                        self.toAndroidDetail();
                    }else{
                        self.toHtmlDetail();
                    }
                }
            });
        };

        /**
         * html详情页
         * @return {[type]} [description]
         */
        AppObject.prototype.toHtmlDetail = function () {
            // alert("/detail?id="+this.product_id+"&oid="+this.store_id+"&oshop_id="+this.oshop_id);
            var oshop_id = 0;
            if (this.oshop_id == "") {
                oshop_id = 0;
            }
            window.location = "http://m.cjwsc.com/detail?id="+this.product_id+"&oid="+this.store_id+"&oshop_id="+oshop_id;
        };

        /**
         * ios详情页
         * @return {[type]} [description]
         */
        AppObject.prototype.toIosDetail = function () {
            if (window.WebViewJavascriptBridge) {
                WebViewJavascriptBridge.callHandler('goDetail', {'pid': this.product_id, 'sid': this.store_id, 'o_shop_id': this.oshop_id}, function (response) {
                        console.log(response);
                });
                return false;
            }else{
                this.toHtmlDetail();
            }
            
        };
        /**
         * 安卓详情页
         * @return {[type]} [description]
         */
        AppObject.prototype.toAndroidDetail = function () {
            if (typeof Android == 'undefined' || Android.openGoodDetail == undefined) {
                this.toHtmlDetail();
            }else{
                Android.openGoodDetail(this.product_id, this.store_id, this.oshop_id);
                return false;
            }
        };

        new AppObject();

        $(document).on('click', '.M_brand_i', function() {
                var cj_id = $(this).data('id');
                window.open("http://www.cjwsc.com/lists2/" + cj_id +".html");
            });
    });